<template>
  <div class="app-container">
    <el-table v-loading="loading" :data="routeproductbomList">
      <el-table-column label="序号" align="center" width="50px">
        <template slot-scope="scope">
          <span>{{ scope.$index + 1 }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="领料单编号"
        align="center"
        width="150px"
        prop="issueCode"
      >
        <template slot-scope="scope">
          <el-button
            type="text"
            @click="handleView(scope.row)"
            >{{ scope.row.issueCode }}</el-button
          >
        </template>
      </el-table-column>
      <el-table-column label="工单编号" align="center" prop="workorderCode" />
      <el-table-column label="物料编码" align="center" prop="productCode" />
      <el-table-column label="物料名称" align="center" prop="productName" />
      <el-table-column label="规格型号" align="center" prop="productSpc" />
      <el-table-column
        label="产线名称"
        width="100"
        align="center"
        prop="lineName"
      />
      <el-table-column
        label="生产数量"
        width="80"
        align="center"
        prop="quantity"
      />
      <!-- <el-table-column label="领料数量" align="center" prop="quantity" /> -->
      <!-- <el-table-column label="领料状态" align="center" width="100px">
        <template slot-scope="scope">
          <span >{{ scope.row.isIssue == '0' ? '未领料':scope.row.isIssue == '1'?'全部领料':scope.row.isIssue == '2'?"部分领料":"--"}}</span>
        </template>
      </el-table-column> -->
      <!-- <el-table-column label="单位" width="80" align="center" prop="unitOfMeasure" /> -->
      <el-table-column
        label="批次号"
        width="80"
        align="center"
        prop="batchCode"
      />
      <el-table-column
        label="领料日期"
        align="center"
        prop="issueDate"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{
            parseTime(scope.row.issueDate, "{y}-{m}-{d} {h}:{m}:{s}")
          }}</span>
        </template>
      </el-table-column>
      <el-table-column label="单据状态" align="center" prop="status">
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.mes_order_status"
            :value="scope.row.status"
          />
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <Detail v-if="open" ref="detailDialog"></Detail>
  </div>
</template>

<script>
import { listIssueheader } from "@/api/mes/pro/workorder";
// import Detail from "./detail.vue"
import Detail from "../../../wm/issue/detail.vue";
export default {
  name: "replenishment",
  components: { Detail },
  props: {
    routeId: null,
    productId: null,
    processId: null,
    optType: null,
    buttonType: null,
    workorderId: null,
  },
  dicts: ["mes_order_status"],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 产品制程物料BOM表格数据
      routeproductbomList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        workorderId: this.workorderId,
        pageNum: 1,
        pageSize: 10,
      },
    };
  },
  created() {
    this.getList();
  },
  watch: {
    workorderId: function (val) {
      this.workorderId = val;
      this.queryParams.workorderId = val;
      if (val) {
        this.getList();
      }
    },
  },
  methods: {
    /** 查询产品制程物料BOM列表 */
    getList() {
      this.loading = true;
      listIssueheader(this.queryParams).then((response) => {
        console.info("response.rows", response.rows);
        this.routeproductbomList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    //点击生成领料单中的编号展示详情
    handleView(row) {
      this.open = true;
      console.log(row, "领料单编号的row");
      this.$nextTick(() => {
        this.$refs.detailDialog.init(row);
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.recordId);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
  },
};
</script>
